package com.jin.webvideo.config.filter.access.rule;

import com.jin.webvideo.entity.SessionStore;

import javax.servlet.http.HttpServletRequest;

public class TokenBucketPathRule extends TokenBucketRule {
    private PathAccessRule rule;
    public TokenBucketPathRule(String key, int frequency, int bucketSize) {
        super(key, frequency, bucketSize);
    }

    public void setRule(PathAccessRule rule) {
        this.rule = rule;
    }

    @Override
    String tokenBucketKey(SessionStore store, HttpServletRequest request) {
        if (rule == null) {
            return request.getRequestURI();
        }
        return rule.match(request.getRequestURI());
    }
}
